﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MMeller.Net.MultiHashmap
{
    internal class ExtendedDictionary<K,V> : IInternalDict<K,V>
    {
        private Dictionary<K, List<V>> dictionary;

        public ExtendedDictionary()
        {
            this.dictionary = new Dictionary<K, List<V>>();
        }

        public void Add(K key, V value)
        {
            if (this.dictionary.ContainsKey(key))
            {
                this.dictionary[key].Add(value);
            }
            else
            {
                this.dictionary[key] = new List<V>();
                this.dictionary[key].Add(value);
            }
        }

        public bool Remove(K key)
        {
            return this.dictionary.Remove(key);
        }

        public bool Remove(K key, V value)
        {
            return this.dictionary[key].Remove(value);
        }

        public void Clear()
        {
            this.dictionary.Clear();
        }

        public V[] getElement(K key)
        {
            return this.dictionary[key].ToArray();
        }

    }
}
